//
//  SPPetingFilterView.swift
//  SparklingPets
//
//  Created by iOS-Czz on 2023/10/26.
//

import UIKit

class SPPetingFilterView: UIView {
    @IBOutlet var firstView: UIView!
    @IBOutlet var secondView: UIView!
    @IBOutlet var thirdView: UIView!
    @IBOutlet var fourthView: UIView!
    @IBOutlet var fiveView: UIView!
    @IBOutlet var sixView: UIView!
    @IBOutlet var sevenView: UIView!
    
    @IBOutlet var firstLabel: UILabel!
    @IBOutlet var secondLabel: UILabel!
    @IBOutlet var thirdLabel: UILabel!
    @IBOutlet var fourthLabel: UILabel!
    @IBOutlet var fiveLabel: UILabel!
    @IBOutlet var sixLabel: UILabel!
    @IBOutlet var allLabel: UILabel!
    var selectIndex = 6
    var bgViews:[UIView] = []
    var nameLabels:[UILabel] = []
    var onSave: ((_ selectIndex:Int) -> Void)?

    override  func awakeFromNib() {
        super.awakeFromNib()
        self.bgViews = [self.firstView,self.secondView,self.thirdView,self.fourthView,self.fiveView,self.sixView,self.sevenView]
        self.nameLabels = [self.firstLabel,self.secondLabel,self.thirdLabel,self.fourthLabel,self.fiveLabel,self.sixLabel,self.allLabel]
        tapAllView("")
    }
    @IBAction func tapFirstView(_ sender: Any) {
        changeSelectStatus(0)
    }
    @IBAction func tapSecondView(_ sender: Any) {
        changeSelectStatus(1)
    }
    @IBAction func tapThirdView(_ sender: Any) {
        changeSelectStatus(2)
    }
    @IBAction func tapFourthView(_ sender: Any) {
        changeSelectStatus(3)
    }
    @IBAction func tapFiveView(_ sender: Any) {
        changeSelectStatus(4)
    }
    @IBAction func tapSixView(_ sender: Any) {
        changeSelectStatus(5)
    }
    @IBAction func tapAllView(_ sender: Any) {
        changeSelectStatus(6)
    }
    
    
//    var selectIndex: Int? {
//        didSet {
//            if selectIndex == 6 {
//                self.sevenView.backgroundColor = THEM_COLOR
//                self.selectIndex = 6
//            }else{
//                changeSelectStatus(selectIndex!)
//            }
//        }
//    }
    
    @IBAction func okAction(_ sender: Any) {
        onSave?(selectIndex)
        self.removeFromSuperview()
    }
    
    func changeSelectStatus(_ selectIndex:Int) {
        self.selectIndex = selectIndex
        for index in 0...self.bgViews.count-1 {
            if index == selectIndex {
                let view = self.bgViews[index]
                view.backgroundColor = THEM_COLOR
                let label = self.nameLabels[index]
                label.textColor = TITLE_COLOR
                if index == 6{
                    label.textColor = .white
                }
            }else{
                let view = self.bgViews[index]
                view.backgroundColor = #colorLiteral(red: 0.9647058824, green: 0.9647058824, blue: 0.9647058824, alpha: 1)
                let label = self.nameLabels[index]
                label.textColor = #colorLiteral(red: 0.1019607843, green: 0.1019607843, blue: 0.1019607843, alpha: 1)
            }
        }
    }
}
